const { getBanner, getGoods } = require("../../api/index")

Page({
    data:{
        value:'',
        swiperOptions:{
            indicatorDots: true,
            autoplay:true,
            interval: 3000,
            duration:1000,
            swiperData:[]
        },
        page:1,
        navData:[
           { 
                text:'数码',
                icon:'gift',
                color:"#ff0000"
            },
            { 
                text:'生鲜',
                icon:'star',
                color:"#ff0000"
            },
            { 
                text:'会员',
                icon:'contact',
                color:"#ff0000"
            },
            { 
                text:'优惠',
                icon:'like',
                color:"#ff0000"
            },
            { 
                text:'充值',
                icon:'phone',
                color:"#ff0000"
            },
            { 
                text:'领券',
                icon:'discount',
                color:"#ff0000"
            },
            { 
                text:'外卖',
                icon:'goods-collect',
                color:"#ff0000"
            },
            { 
                text:'美食',
                icon:'shop-collect',
                color:"#ff0000"
            }
        ],
        goodsData:[]
    },
    http(page){
        getGoods({page}).then((res) => {
            if(!res.data.msg) {
                console.log(res.data.data.result);
                this.setData({
                    goodsData:this.data.goodsData.concat(res.data.data.result),
                    page:this.data.page + 1
                })  
            } else {
                // 提示没有数据了
                wx.showToast({
                  title: '暂无新数据',
                  icon:'success',
                  duration:2000
                })
            }
        })
    },
    /**
     * 点击搜索框跳转
     */
    clickSearch(){
        console.log("转");
        wx.navigateTo({
          url: '/pages/search/search',
        })
    },
    onLoad(){
        getBanner().then((res)=>{
            // console.log(res.data.data.result);
            this.setData({
                swiperData:res.data.data.result
            })
        })
        this.http(this.data.page)
    },
    onReachBottom(){
        this.http(this.data.page)
    },
})